<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">

    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">

    <meta name="viewport" content="width=device-width"/>
    <meta name="viewport" content="initial-scale=1.0,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes">

    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="/vendor/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="/vendor/font-awesome/css/font-awesome.min.css">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" href="/css/fontastic.css">
    <!-- Google fonts - Poppins -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,700">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="/css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="/css/custom.css">
    <!-- Favicon-->
    <link rel="shortcut icon" href="img/favicon.ico">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script type="text/javascript">
        function toLogin() {
            var userName = $.trim($("#userName").val());
            var password = $.trim($("#password").val());
            console.log('userName:' + userName + 'password:' + password);

            if (userName == "") {
                alert("用户名不能为空");
                return false;
            }
            if (password == "") {
                alert("密码不能为空");
                return false;
            }
            if (userName.length < 6 || userName.length > 15) {
                alert("用户名长度不能小于6或者大于15");
            }
            if (password.length < 6 || password.length > 15) {
                alert("密码长度不能小于6或者大于15");
            }
            $.ajax({
                type: "POST",
                url: "/userManagement/userLogin",
                data: {"userName": userName, "password": password},
                cache: false,
                dataType: "json",
                complete: function (ret) {
                    var jsonVar = JSON.parse(ret.responseText);

                    if (jsonVar.status == 1 && jsonVar.code == "0000") {
                        alert(jsonVar.message);
                        setTimeout(window.location.href = '/userManagement/mainIndex', 3);
                    } else {
                        $("#userName").val("");
                        $("#password").val("")
                        alert(jsonVar.message);
                    }
                }
            });
        }
    </script>
</head>
<body>
<div class="page login-page">
    <div class="container d-flex align-items-center">
        <div class="form-holder has-shadow">
            <div class="row">

                <div class="col-lg-6 bg-white">
                    <div class="form d-flex align-items-center">
                        <div class="content">
                            <form method="post" class="form-validate">
                                <div class="form-group">
                                    <input id="userName" type="text" name="userName"  maxlength="15"
                                           required data-msg="请输入你的账号"
                                           onkeyup="value=value.replace(/[^0-9a-zA-Z]/g,'')" class="input-material">
                                    <label for="userName" class="label-material">账号</label>
                                </div>
                                <div class="form-group">
                                    <input id="password" type="password"  name="password" maxlength="15"
                                           required data-msg="请输入你的密码"
                                           onkeyup="value=value.replace(/[^0-9a-zA-Z]/g,'')"
                                           class="input-material">
                                    <label for="password" class="label-material">密码</label>
                                </div><a id="login" class="btn btn-primary" onclick="toLogin();">Login</a>
                            </form>
                            <small>没有账号</small><a href="/userManagement/registerIndex">我要注册</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
<!-- JavaScript files-->
<script src="/vendor/jquery/jquery.min.js"></script>
<script src="/vendor/popper.js/umd/popper.min.js"> </script>
<script src="/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="/vendor/jquery.cookie/jquery.cookie.js"> </script>
<script src="/vendor/chart.js/Chart.min.js"></script>
<script src="/vendor/jquery-validation/jquery.validate.min.js"></script>
<!-- Main File-->
<script src="/js/front.js"></script>

</body>
</html>